﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class EditCategory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Label10.Visible = false;
            Button2.Attributes.Add("onclick","confirm('Are you sure you want to proceed?')");
            LoadData();
        }
      
      
    
      
    }

    private void LoadData()
    {

        int id = int.Parse(Request.QueryString["id"].ToString());
        ManagementPayment m = new ManagementPayment();
        DropDownList1.DataSource = m.GetSubCategory();
        DropDownList1.DataBind();
        ORANGE_PROJECTModel.PaymentMethod p = (ORANGE_PROJECTModel.PaymentMethod)m.GetPayment(id);
        DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(p.SubCategoryID.ToString()));
        txtID.Text = id.ToString();
        txtName.Text = p.PaymentName;
        txtPriceretal.Text = p.PriceRental.ToString();
        txtNote.Text = p.Note;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ManagementPayment m = new ManagementPayment();
        int id = int.Parse(Request.QueryString["id"].ToString());
        if (m.UpdatePaymentMethod(Int32.Parse(txtID.Text), txtName.Text, Double.Parse(txtPriceretal.Text), txtNote.Text, Int32.Parse(DropDownList1.SelectedValue)))
        {
            
            Label10.Visible = true;
            Label10.Text = "<span style='color:green;font-weight: bold;'>Update Succerfully :)</span>";
            LoadData();
        }
        else {
            Label10.Visible = true;
            Label10.Text = "<span style='color:red;font-weight: bold;'>Update Failed (:</span>";
        }
        
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        int id = int.Parse(Request.QueryString["id"].ToString());
        ManagementPayment m = new ManagementPayment();
        if (m.DeletePayment(id))
        {
            Response.Redirect("ManagementPayment.aspx");
        }
        else {
            Label10.Visible = true;
            Label10.Text = "<span style='color:red;font-weight: bold;'>Check Fkey (:</span>";
        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {

    }
}